<template>
    <div>
        <van-nav-bar title="首页" />
        <van-search v-model="vals" show-action label="地址" placeholder="请输入搜索关键词" @search="onSearch">
            <template #action>
                <div @click="onClickButton">搜索</div>
            </template>
        </van-search>
        <div v-for="item in searchData">
            <router-link :to="{ name: 'det', params: { goods_id: item.goods_id } }">
                <van-card :num="item.goods_number" :price="item.goods_price" :title="item.goods_name" />
            </router-link>

        </div>
    </div>
</template>

<script setup>
let vals = ref('')
import { searchApi } from '@/api/api';
import { ref, watch } from 'vue';
let searchData = ref([])
watch(vals, (val) => {
    searchApi(val).then((res) => {
        console.log(res);
        searchData.value = res.data.message.goods
    })
})
</script>

<style lang="scss" scoped></style>